using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using GrrrControls;
using SAGE.Utilities;

namespace SAGE.Agent
{
  public class CircleAgent : IInteractorAgent
  {
    #region Members

    protected GrrrSphere _grrrSphere;
    protected DateTime _creationTime;
    protected Point3D _location;
    protected Point3D _velocity;
    protected Point3D _offset;
    protected double _mass;

    #endregion

    #region IAgent Members

    public Point3D Offset
    {
      get { return _offset; }
    }

    public DateTime Creation
    {
      get { return _creationTime; }
    }

    #endregion

    #region IInteractorAgent Members

    public Point3D Location
    {
      get { return _location; }
      set { _location = value; }
    }

    public Point3D Velocity
    {
      get { return _velocity; }
      set { _velocity = value; }
    }

    public double Mass
    {
      get { return _mass; }
      set { _mass = value; }
    }

    #endregion

    #region Constructor

    public CircleAgent(Point3D position, double radius, Color color)
    {
      _creationTime = DateTime.Now;
      _location = position;
      _velocity = new Point3D(1, .6, .4);
      _grrrSphere = new GrrrSphere(position.x, position.y, position.z, radius, color);
      _offset = new Point3D(radius, radius, radius);
      _mass = 10;
    }

    #endregion
  
    #region IAgent Methods (Update)

    public void Update(TimeSpan gameTime, Physics physics)
    {
      _location.x = _location.x + _velocity.x;
      _location.y = _location.y + _velocity.y;
      _location.z = _location.z + _velocity.z;

      _velocity.z = _velocity.z - physics.Gravity;

      this._grrrSphere.SetPosition(_location.x, _location.y, _location.z);

      Collision collision = physics.CheckCollisions(this);

      if (collision.CollisionAxis != CollisionAxis.None)
      {
        //_velocity.x = _velocity.x - (.05 * _mass);
        //_velocity.y = _velocity.y - (.05 * _mass);
        //_velocity.z = _velocity.z - (.05 * _mass);

        if (collision.CollisionAxis == CollisionAxis.X)
        {
          _velocity.x = -(_velocity.x);
        }
        else if (collision.CollisionAxis == CollisionAxis.Y)
        {
          _velocity.y = -(_velocity.y);
        }
        else if (collision.CollisionAxis == CollisionAxis.Z)
        {
          _velocity.z = -(_velocity.z);
        }
      }
    }

    #endregion
  }
}
